# -*- coding: utf-8 -*- 

import Database

class MUsers(object):
    def __init__(self):
        pass
    
    @staticmethod
    def GetNames():
        recs = Database.MUser.select()
        return [rec.name for rec in recs]
    
    @staticmethod
    def Has(name):
        return Database.MUser.selectBy(name = name).count() > 0
    
    @staticmethod
    def Find(name):
        return Database.MUser.selectBy(name = name)[0]
    
class MPartTypes(object):
    def __init__(self):
        pass
    
    @staticmethod
    def GetNames():
        recs = Database.MPartType.select()
        return [rec.name for rec in recs]
    
    @staticmethod
    def GetNamesAsCategory(category):
        recs = Database.MPartType.selectBy(category = MPartCategory.Find(category))
        return [rec.name for rec in recs]
    
    @staticmethod
    def Find(name):
        return Database.MPartType.selectBy(name = name)[0]
    
    @staticmethod
    def FindAsBarcode(code):
        return Database.MPartType.selectBy(barcode = code)[0]
    
class MPartCategory(object):
    def __init__(self):
        pass
    
    @staticmethod
    def GetNames():
        recs = Database.MPartCategory.select()
        return [rec.name for rec in recs]
    
    @staticmethod
    def Find(name):
        return Database.MPartCategory.selectBy(name = name)[0]
    
class E18Entities(object):
    def __init__(self):
        pass
    
    @staticmethod
    def GetNames():
        recs = Database.MEntity.select()
        return [rec.name for rec in recs]
    
    @staticmethod
    def Has(name):
        return Database.MEntity.selectBy(name = name).count() > 0
    
    @staticmethod
    def Find(name):
        return Database.MEntity.selectBy(name = name)[0]
    
    @staticmethod
    def FindAsCode(code):
        return Database.MEntity.selectBy( code = code)[0]